<template>
  <a-row :class="['p-4', `${prefixCls}--box`]" type="flex" :gutter="10">
    <a-col :xl="6" :lg="24" :md="24" style="margin-bottom: 10px">
      <AreaLeftTree ref="leftTree" @select="onTreeSelect" @rootTreeData="onRootTreeData" />
    </a-col>
    <a-col :xl="18" :lg="24" :md="24" style="margin-bottom: 10px">
      <div style="height: 100%;" :class="[`${prefixCls}`]">
        <a-tabs v-show="areaData != null" defaultActiveKey="base-info">
          <a-tab-pane tab="基本信息" key="base-info" forceRender style="position: relative">
            <div style="padding: 20px">
              <AreaFormTab :data="areaData" :rootTreeData="rootTreeData" @success="onSuccess" />
            </div>
          </a-tab-pane>
          <a-tab-pane tab="查看地图" key="role-info">
            <div style="padding: 0 20px 20px">
              <AreaMapTab :data="areaData" />
            </div>
          </a-tab-pane>
        </a-tabs>
        <div v-show="areaData == null" style="padding-top: 40px">
          <a-empty description="尚未选择地块" />
        </div>
      </div>
    </a-col>
  </a-row>
</template>

<script lang="ts" setup name="system-area">
import { provide, ref } from 'vue';
import { useDesign } from '/@/hooks/web/useDesign';
import AreaLeftTree from './components/AreaLeftTree.vue';
import AreaFormTab from './components/AreaFormTab.vue';
import AreaMapTab from './components/AreaMapTab.vue';

const { prefixCls } = useDesign('area-manage');
provide('prefixCls', prefixCls);

// 给子组件定义一个ref变量
const leftTree = ref();

// 当前选中的地块信息
const areaData = ref({});
const rootTreeData = ref<any[]>([]);

// 左侧树选择后触发
function onTreeSelect(data) {
  console.log('onTreeSelect: ', data);
  areaData.value = data;
}

// 左侧树rootTreeData触发
function onRootTreeData(data) {
  rootTreeData.value = data;
}

function onSuccess() {
  leftTree.value.loadRootTreeData();
}
</script>

<style lang="less">
@import './index.less';
</style>
